#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>

#define MAX_SIZE             10

int main(int argc, char *argv[])
{
    int n;
    int fd[2];
    pid_t pid;
    char line[MAX_SIZE];
	int fd_test;

    if (pipe(fd) < 0)
        perror("pipe error");
    if ((pid = fork()) < 0) {
        perror("fork error");
    } else if (pid > 0) {
        close(fd[0]); 
		close(STDOUT_FILENO);
		dup2(fd[1], STDOUT_FILENO);
		printf("1234567890\n");
		printf("1234567890\n");
		printf("1234567890\n");
		printf("1234567890\n");
		printf("1234567890\n");
    } else {
        close(fd[1]);
		fd_test = open("1", O_RDWR | O_CREAT, 0777);

		while((n = read(fd[0], line, MAX_SIZE)) > 0)
			if(write(fd_test, line, n) != n)
				perror("write error");
    }
	close(fd_test);

    return 0;
}
